<?php
namespace Home\Controller;
use Think\Controller;
header('content-type:text/html;charset="UTF-8"');
class SearchController extends Controller {
    public function index(){
        $search=I('get.search');
        $db=M('product');
        if (!empty($search)) {
            $key ['title'] = array ('like','%' . $search . '%');
            $data=$db->where($key)->select();
        }
        foreach ($data as $key => $value) {
            $value['images']=json_decode($value['images'],true);
            $data[$key]['images']=$value['images'][0];
        }
        $this->assign('data',$data);  

        
        $dc=M('shopcart');//统计购物车的数量
        $uid=$_SESSION['uid'];
        if (!empty($uid)) {
            $dataCount=$dc->where("uid={$uid}")->select();
            $count=count($dataCount);
            $this->assign('count',$count);  
        }	
        $this->display();
    }
   
   
}